package com.example.demo.pojo;

import lombok.Data;
import lombok.Getter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
/**
 * @author luolinila
 */
@Data
public class PokerSet implements Serializable {
    @Getter
    public HashSet<Poker> outNot = new HashSet<>();
    public HashSet<Poker> outAlso = new HashSet<>();
    public PokerSet() {
        for (String value : Poker.values) {
            for (String color : Poker.colors) {
                outNot.add(new Poker(value, color));
            }
        }
    }

    //从未发牌序列中发出 n 张牌
    public List<Poker> faPai (int n) {
        //取 n 和 未发牌序列长度 中最小
        n = Math.min(n, outNot.size());
        List<Poker> pokers = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            pokers.add(faPai());
        }
        return pokers;
    }

    //随机发出一张牌
    public Poker faPai() {
        Random r = new Random();
        Poker[] arr = outNot.toArray(new Poker[outNot.size()]);
        Poker p = arr[r.nextInt(arr.length)];
        outNot.remove(p);
        outAlso.add(p);
        return p;
    }


}
